﻿using System;
using System.IO;
using UnityEngine;

namespace HurricanePackage
{
    public  class LocalResAssetObject : AssetObject
    {
        private GameObject m_uiGameObject;
        private readonly string m_resPath;
        private readonly string m_uiName;


        public LocalResAssetObject(string _resPath,string _uiAssetName)
        {
            m_uiName = _uiAssetName;
            m_resPath = Path.Combine(_resPath, _uiAssetName);
        }


        public override GameObject GameObj { get => m_uiGameObject; }

        protected override void _LoadOp()
        {
            GameObject go = Resources.Load<GameObject>(m_resPath);
            if (go != null)
            {
                m_uiGameObject = GameObject.Instantiate(go);
                //设置加载完成
                _SetLoadDone();
            }
            else
            {
                Debug.LogError($"{AssetName}加载失败");
            }

        }

        protected override void _DestroyOp(Action _doneAction)
        {
            if(_doneAction != null)
                _doneAction.Invoke();
            GameObject.Destroy(m_uiGameObject);
        }

        public override string AssetName
        {
            get => m_uiName;
        }
    }
}